package com.su.lightthings.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.content.res.ColorStateList
import android.view.ViewGroup
import android.widget.BaseAdapter
import androidx.core.content.ContextCompat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.QuickViewHolder
import com.google.android.material.card.MaterialCardView
import com.su.lightthings.R
import com.su.lightthings.bean.HomeFunctionBean

class HomeFunctionAdapter : BaseQuickAdapter<HomeFunctionBean, QuickViewHolder>() {
    override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: HomeFunctionBean?) {

        val card = holder.getView<MaterialCardView>(R.id.card_view)
        card.setCardBackgroundColor(ColorStateList.valueOf(ContextCompat.getColor(context,item!!.color)))
        holder.setImageResource(R.id.iv_icon, item.icon)
        holder.setText(R.id.tv_title, item.title)
        holder.setText(R.id.tv_data, item.data)
        holder.setText(R.id.tv_unit, item.unit)
    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): QuickViewHolder =
        QuickViewHolder(R.layout.adapter_home_function, parent)
}